<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
	<#include "/common/header.ftl">
	<title>投资活动统计</title>
</head>
<body>
<input type="hidden" id="activityId" value="${id}">
<div id="mainDataGrid" style="width:100%"></div>
<div id="toolBar" style="width:100%;">
	<table>
		<tr>
			<td>投资产品</td>
			<td>
				<select class="easyui-combobox" id="borrowTypes" data-options="panelHeight:'auto',editable:false,required:true">
					<option value="">请选择</option>
					<#if borrowTypes ??>
						<#list content.borrowType as borrowType>
                            <option value="${borrowType.value}">${borrowType.text}</option>
						</#list>
					</#if>
					<#--<c:forEach items="${borrowTypes}" var="borrowType">
		 					<option value="${borrowType.value}">${borrowType.text}</option>
		 			</c:forEach>-->
				</select>
			</td>
			<td>投资平台</td>
			<td>
				<select class="easyui-combobox" id="publishPlats" data-options="panelHeight:'auto',editable:false,required:true">
					<option value="">请选择</option>
				<#if platForms ??>
					<#list content.platForms as platForms>
                        <option value="${platForms.value}">${platForms.text}</option>
					</#list>
				</#if>
					<#--<c:forEach items="${platForms}" var="platForm">
		 					<option value="${platForm.value}">${platForm.text}</option>
		 			</c:forEach>-->
				</select>
			</td>
			<td>奖池ID</td>
			<td>
				<input id="ticketId" type="text" class="value">
			</td>
			<td>用户手机号</td>
			<td>
				<input id="userPhone" type="text" class="value">
			</td>
			<td>用户ID</td>
			<td>
				<input id="userId" type="text" class="value">
			</td>
		</tr>
		<tr>
			<td>投资区间</td>
			<td>
				<select class="easyui-combobox" id="investAmountPeriods" data-options="panelHeight:'auto',editable:false,required:true">
					<option value="">请选择</option>
				<#if periodsList ??>
					<#list content.periodsList as periodsList>
                        <option value="${periodsList.value}">${periodsList.text}</option>
					</#list>
				</#if>
					<#--<c:forEach items="${periodsList}" var="period">
		 					<option value="${period.value}">${period.text}</option>
		 			</c:forEach>-->
				</select>
			</td>
			<td>投资期限</td>
			<td>
				<select class="easyui-combobox" id="investMonthPeriods" data-options="panelHeight:'auto',editable:false,required:true">
					<option value="">请选择</option>
					<option value="1">一个月</option>
					<option value="3">三个月</option>
					<option value="6">六个月</option>
					<option value="12">十二个月</option>
					<option value="24">二十四个月</option>
				</select>
			</td>
			<td>奖池类型</td>
			<td>
				<select class="easyui-combobox" id="ticketType" data-options="panelHeight:'auto',editable:false,required:true">
					<option value="">请选择</option>
	                <option value="1">实物券</option>
	                <option value="2">紅包</option>
	                <option value="3">加息券</option>
	                <option value="4">体验券</option>
	                <option value="5">费用抵用券</option>
	                <option value="6">三方红包</option>
	                <option value="7">现金</option>
	                <option value="9">票券</option>
	                <option value="10">虚拟现金红包</option>
		            <option value="11">返点现金红包</option>
				</select>
			</td>
			<td>发放时间</td>
			<td>
	             <input type="text" id="createStartTime" class="easyui-datebox"/>
	         </td>
	         <td>--</td>
	         <td>
	             <input type="text" id="createEndTime"  class="easyui-datebox"/>
	         </td>
	         <td colspan="2">
                 <center>
	                 <a href="#" id="searchLink" class="easyui-linkbutton" iconCls="icon-search">查询</a>
	                 <a href="#" onclick="doExport()" class="easyui-linkbutton" iconCls="icon-undo">导出</a> 	 
                 </center>
            </td>
		</tr>
	</table>
	<table>
	<tr>
		<td align="left">
			<a href="#" onclick="openDetails()">展开/关闭</a>已发放奖励:
		</td>
		<td>
			<table id="ticketInfoList"  style="display: none;border:1px solid #aaa;border-collapse:collapse;">
					<#--<c:forEach items="${ticketInfo}" var="info" varStatus="num">
				<tr>
					<td align="left">${info.typeName}：</td>
					<td align="left">${info.title}：</td>
					<td align="left">${info.generateNum} </td>
					<td align="left">已发放：${info.sendCount} </td>
				</tr>
					</c:forEach>-->
			<#if ticketInfo ??>
				<#list content.ticketInfo as ticketInfo>
                    <tr>
                        <td align="left">${ticketInfo.typeName}：</td>
                        <td align="left">${ticketInfo.title}：</td>
                        <td align="left">${ticketInfo.generateNum} </td>
                        <td align="left">已发放：${ticketInfo.sendCount} </td>
                    </tr>
				</#list>
			</#if>
				<tr>
					<td align="left">投资额：${totalAmount} </td>
					<td align="left">投资人数：${userCount} </td>
					<td align="left">投资笔数：${investCount} </td>
					<td align="left"> </td>
				</tr>
				</table>
			</td>
		</tr>
	</table>
</div>
<script>
	$(function () {
	    // 初始化数据表格
		renderDataGrid();
		// 搜索按钮监听
        $("#searchLink").click(doSearch);
	})

	function renderDataGrid(){
		$("#mainDataGrid").datagrid({
			url:"/activity/queryInvestActInfo",
			queryParams:{activityId:$('#activityId').val()},
			loadMsg: "loading data...",
            fit:true,
            pagination:true,
            singleSelect:true,
            columns:[
                     [
						{field: 'id', title: 'ID',width:50, align: 'center'},
						{field: 'userId', title: '用户Id',width:100, align: 'center'},
						{field: 'mobilePhone', title: '手机号',width:100, align: 'center'},
						{field: 'userName', title: '用户姓名',width:100, align: 'center'},
						{field: 'accessPort', title: '投资平台',width:100, align: 'center',formatter:function(val,rec){ 
							if (val == 1){ 
								return 'PC'; 
							} else if(val == 2){ 
								return 'TOUCH'; 
							} else if(val == 3){ 
								return 'H5'; 
							} else if(val == 4){ 
								return 'ANDROID'; 
							} else if(val == 5){ 
								return 'IOS'; 
							}else{
								return '';
							}
						} },
						{field: 'investType', title: '投资产品',width:100, align: 'center',formatter:function(val,rec){ 
							if (val == 2){ 
								return '定期宝'; 
							} else if(val == 0){ 
								return '散标'; 
							} else if(val == 1){ 
								return '活期宝'; 
							} else if(val == 3){ 
								return '新手标'; 
							} else if(val == 4){ 
								return '苹果专享标'; 
							} else if(val == 5){ 
								return '游艇投资'; 
							}else if(val == 6){ 
								return '酒店投资'; 
							}else if(val == 8){ 
								return '秒借'; 
							}else if(val == 9){ 
								return '有用分期'; 
							}else if(val == 10){ 
								return '车信宝'; 
							}else{
								return '集合包';
							}
						} },
						{field: 'periods', title: '投资期限',width:100, align: 'center'},
						{field: 'amount', title: '投资金额',width:100, align: 'center',formatter:function(val,rec,index){ 
							if (val != null){ 
								return val; 
							} else {
								return '';
							}
						}},
						{field: 'typeName', title: '奖池类型',width:100, align: 'center'},
						{field: 'ticketAmount', title: '奖券额度',width:100, align: 'center'},
						{field: 'ticketId', title: '奖券ID',width:100, align: 'center'},
						{field: 'createTime', title: '发放时间',width:150, align: 'center'}
                     ]     
            ],
            onLoadSuccess:function(data){
                if (data.errorMsg){
                	$.messager.alert('错误',data.errorMsg);
                }
            },
            onLoadError:function(){
            	$.messager.alert('错误',"错误");
                   
            },
            toolbar: "#toolBar"
		});
	}
	
	function  openDetails(){
		if($("#ticketInfoList").css('display')=='none'){
			$("#ticketInfoList").css('display','block');
			doSearch();
		}else{
			$("#ticketInfoList").css('display','none');
			doSearch();
		}
	}
	
	function doSearch(){
		$('#mainDataGrid').datagrid('reload',{
			activityId:$('#activityId').val(),
			borrowTypes:$('#borrowTypes').combobox("getValue"),
			publishPlats:$('#publishPlats').combobox("getValue"),
			ticketId:$('#ticketId').val(),
			userPhone:$('#userPhone').val(),
			userId:$('#userId').val(),
			investAmountPeriod:$('#investAmountPeriods').combobox("getValue"),
			investMonthPeriod:$('#investMonthPeriods').combobox("getValue"),
			ticketType:$('#ticketType').combobox("getValue"),
			createStartTime: $('#createStartTime').datebox("getValue"),
        	createEndTime: $('#createEndTime').datebox("getValue")
		});
	}
	
	 /**
	   *导出
	   */
	  function doExport(){
	       var rows = $("#mainDataGrid").datagrid("getRows");
	       if(rows.length==0){
	           $.messager.alert('错误',"暂无数据导出！");
	       }else{
	          /*<%--  var url = "<%=basePath %>/exportData/exportInvestActDetail?activityId=" + $('#activityId').val() + "&borrowTypes=" + $('#borrowTypes').combobox("getValue")
	                   + "&publishPlats=" + $('#publishPlats').combobox("getValue") + "&ticketId=" + $('#ticketId').val() + "&userPhone=" + $('#userPhone').val()
	                   + "&userId=" + $('#userId').val() + "&investAmountPeriod=" + $('#investAmountPeriods').combobox("getValue")
	                   + "&investMonthPeriod=" + $('#investMonthPeriods').combobox('getValue')+ "&ticketType=" + $('#ticketType').combobox('getValue')
	                   +"&createStartTime=" + $('#createStartTime').datetimebox("getValue")+"&createEndTime=" + $('#createEndTime').datetimebox("getValue");
	           window.open(url); --%>*/
	           createXLS()
	       }
	  }
	  function createXLS(){
	    	$.messager.progress({text:"正在处理，请不要刷新页面..."}); 
	    	$.ajax(
	    		{
	    			url:"<%=basePath %>/dataExport/exportInvestActDetail",
	    			data:{
	    				activityId:$('#activityId').val(),
	    				borrowTypes:$('#borrowTypes').combobox("getValue"),
	    				publishPlats:$('#publishPlats').combobox("getValue"),
	    				ticketId:$('#ticketId').val(),
	    				userPhone:$('#userPhone').val(),
	    				userId:$('#userId').val(),
	    				investAmountPeriod:$('#investAmountPeriods').combobox("getValue"),
	    				investMonthPeriod:$('#investMonthPeriods').combobox('getValue'),
	    				ticketType: $('#ticketType').combobox('getValue'),
	    				createStartTime:$('#createStartTime').datetimebox("getValue"),
	    				createEndTime:$('#createEndTime').datetimebox("getValue")
	    			},
	    			dataType:"json",
	    			success:function(data){
	    				$.messager.progress('close');
	    				if(data.code ==1){
	    					var url = "<%=basePath %>/dataExport/downLoadFile?fileName=" + data.obj;
	    					$.messager.confirm("操作提示", "您确定要执行操作吗？", function (data) {
	      			            if (data) {
	      							window.open(url);
	      			            }
	      			        });
	    				}else{
	    					$.messager.alert('错误',data.msg);
	    				}
	    			}
	    		}		
	    	);
	    }
</script>
</body>
</html>